package example.controller;

import example.common.Result;
import example.service.ISecondmentDistributeInfoService;
import example.service.ISecondmentService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private ISecondmentService secondmentService;

    @Resource
    private ISecondmentDistributeInfoService secondmentDistributeInfoService;

    //    借调发起文件
    @GetMapping("/download/{id}")
    public void downloadSecondmentFile(@PathVariable("id") Long secondmentId, HttpServletResponse response) {
        secondmentService.downloadSecondmentFile(secondmentId, response);
    }

    @GetMapping("/confirm/{id}")
    public void downloadConfirm( @PathVariable("id") Long secondmentId,HttpServletResponse response) {
        secondmentService.downloadConfirm(secondmentId, response);
    }

    @GetMapping("/confirm/department")
    public void downloadConfirm( @RequestParam(name = "secondmentId") String secondmentId,@RequestParam(name = "departmentId") String departmentId,HttpServletResponse response) {
        secondmentDistributeInfoService.downloadConfirm(Long.parseLong(secondmentId),Long.parseLong(departmentId), response);
    }
    @GetMapping("/confirmname/department")
    public Result downloadConfirmName( @RequestParam(name = "secondmentId") String secondmentId,@RequestParam(name = "departmentId") String departmentId) {
        return secondmentDistributeInfoService.getConfirmName(Long.parseLong(secondmentId),Long.parseLong(departmentId));
    }
    //被借调部门上传回函
    @PostMapping("/response/file")
    public Result uploadResponseFile(List<MultipartFile> files, Long departmentId, Long secondmentId) {
        return secondmentDistributeInfoService.uploadResponseFile(files, departmentId, secondmentId);
    }

    @PostMapping("/temp/file")
    public Result uploadTempFile(List<MultipartFile> files, Long secondmentId) {
        return secondmentDistributeInfoService.uploadTempFile(files, secondmentId);
    }



    public Result response() {
        return null;
    }

}
